#ifndef CHARACTER_H
#define CHARACTER_H

#include <SFML/Graphics.hpp>
#include <string>
#include <deque>
#include <unistd.h>
#include "tinyxml.h"

class Level; // because of recursive inclusion...

using namespace std;
using namespace sf;

#define CHARACTER_XML     "character.xml"
#define FRAMES_PER_SECOND 5

enum Direction { LEFT, UP, RIGHT, DOWN };

class Animation {
public:
    Animation() {}
    Animation(int count,
              int left,
              int top,
              int right,
              int bottom);
    Animation(TiXmlElement* frameset);
    
    int count;
    int left;
    int top;
    int right;
    int bottom;
};

class Animated {
public:
    Animated(string name);
    ~Animated();
    Sprite& getSprite();

protected:
    void animate(Animation &animation);
    void animate(TiXmlElement* frameset);
    
    string            path;
    TiXmlDocument*    xmlDoc;
    TiXmlElement*     xml;
    Sprite            sprite;
    deque<Rect<int> > animationQueue;
    Clock             clock;
    int               busy;
};

class Character : public Animated {
    friend class Level;

public:
    Character(string name, Vector2f& defaultPosition, Level* level);

    bool      isAlive();
    bool      isBusy();
    void      walk(Direction direction);
    void      jump();
    void      attack(string name);
    void      hit(int damage);
    int       getDistanceFrom(Character* enemy);
    string    getRank();
    string    getName();
    int       getMaxHealth();
    int       getHealth();
    Vector2f& getDefaultPosition();
    int       getX();
    int       getY();
    Direction getOrientation();
    void      setX(int x);
    void      setY(int y);

protected:
    Level*    level;
    string    rank;
    string    name;
    int       maxHealth;
    int       currentHealth;
    Vector2f  defaultPosition;
    int       x;
    int       y;
    Direction orientation;
};

class Hero : public Character {
public:
    void walk(Direction direction);
};

#endif
